/*
 * UserInterface.hpp
 *
 *  Created on: 26-12-2010
 *      Author: Przemek
 */

#pragma once

#include "customUI/GlobalInfoPanel.hpp"
#include "customUI/ElementInfoPanel.hpp"
#include "customUI/ControlPanel.hpp"
#include "customUI/WorldViewControl.hpp"
#include "gui/Container.hpp"
#include "gui/Control.hpp"
#include "listener/SelectElementMouseListener.hpp"
#include "pch.hpp"

/*
 * View-only class which creates and positions every needed control on the screen. It's also a
 * converter which creates MouseEvent and KeyEvent based on SDL events and dispatches it to a proper
 * child control.
 */
class UserInterface
{
	private:
		static const float LEFT_PANEL_WIDTH;
		bool pressed;
		Dimension windowSize;
		Container rootContainer;
		Container* leftPanel;
		Container* rightPanel;
		Control* controlWithFocus;

		GlobalInfoPanel* globalInfoPanel;
		ElementInfoPanel* elementInfoPanel;
		ControlPanel* controlPanel;
		WorldViewControl* worldViewControl;
		SelectElementMouseListener* selectElementMouseListener;

	public:
		UserInterface(const Dimension& windowSize);
		// called from window class
		void windowSizeChanged(const Dimension& windowSize);
		void processMouseButtonEvent(const SDL_MouseButtonEvent& event);
		Vector switchFocusControlAndTransformToItsCoordinates(const Vector& point);
		void processMouseMotionEvent(const SDL_MouseMotionEvent& event);
		void processKeyEvent(const SDL_KeyboardEvent& event);
		KeyListener::EventArguments createKeyArgumentsBasedOnEvent(const SDL_KeyboardEvent& event);
		// updates other panels state and world state
		void updateWithDeltaTime(float deltaTimeInSeconds);
		void draw();

	private:
		Container* createLeftPanel();
		Container* createInfoPanel();
		Container* createControlPanel();
		Container* createRightPanel();
};
